﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevTeam;

using System;
using System.Drawing;

namespace ConfExpert.Forms.SatinAlma
{
    public partial class KstAnaliz : XForm
    {
        public KstAnaliz()
        {
            InitializeComponent();
        }

        private void KAnaliz_Load(object sender, EventArgs e)
        {
            ((RepositoryItemComboBox)cmb.Edit).TextEditStyle = TextEditStyles.DisableTextEditor;
            ((RepositoryItemComboBox)cmb.Edit).SelectedIndexChanged += new EventHandler(cmb_SelectedIndexChanged);
            cmb.EditValue = "Durum2Id";
            gv1.BestFitColumns();

        }

        void cmb_SelectedIndexChanged(object sender, EventArgs e)
        {
            gv1.Init("GetKstAnaliz", sel);
            gv1.AddDetailGrid(gv2, cmb.EditValue.ToStr());
            gv1.FormatAsNumber(0, "Mt", "YuklenenMt");
            gv2.FormatAsNumber(0, "Mt", "YuklenenMt");
            gv1.AddSummary("Mt", "YuklenenMt");
            gv2.AddSummary("Mt", "YuklenenMt");

            gv1.RowCellStyle -= new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gv1_RowCellStyle);
            gv1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gv1_RowCellStyle);

            gv2.BestFitColumns();
        }

        void gv1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == cmb.EditValue.ToStr())
                e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
        }

        public int sel
        {
            get
            {
                int ret = -1;
                switch (cmb.EditValue.ToStr())
                {
                    case "Durum2Id": ret =  0; break;
                    case "BrandId": ret =  1; break;
                    case "SezonId": ret =  2; break;
                    case "OrderRef": ret =  3; break;
                    case "UreticiId": ret =  4; break;
                    case "ProductId": ret =  5; break;
                    case "StokKodu": ret =  6; break;
                    case "UreticiKodu": ret =  7; break;
                    case "MusteriKodu": ret =  8; break;
                    case "KstCategoryId": ret =  9; break;
                    case "SipVerenId": ret =  10; break;
                    case "ETAVarisTarihi": ret =  11; break;
                    case "Tip": ret =  12; break;
                    case "CustomerId": ret =  13; break;
    
                }
                return ret;
            }
        }
    }
}